package com.turing.post.account.impl;

import java.math.BigInteger;
import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.account.util.BankAssoc;
import com.turing.post.account.util.BankAssocDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;

@Stateless(mappedName = "account.impl.BankAssocDaoImpl")
@Remote
@Local
public class BankAssocDaoImpl implements BankAssocDao {

	/**
	 * 实体管理器
	 * 
	 * @see javax.persistence.EntityManager
	 */
	@PersistenceContext
	protected EntityManager _em;
	
	@Override
	public void delete(BankAssoc ba) throws PCPSApplicationException {
		GeneralDao.remove(_em, ba);
	}

	@SuppressWarnings("unchecked")
	@Override
	public BankAssoc getBankAssoc(BigInteger bankManageId,
			BigInteger masterAccNo) {
		String sql = "select * from BankAssoc t where t.bankmanageid=?1 "
				+ " and t.masteraccno=?2 ";
		Query query = _em.createNativeQuery(sql, BankAssoc.class);
		query.setParameter(1, bankManageId);
		query.setParameter(2, masterAccNo);
		List<BankAssoc> list = query.getResultList();
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void insert(BankAssoc ba) throws PCPSApplicationException {
		GeneralDao.insert(_em, ba);
	}

	@Override
	public void update(BankAssoc ba) throws PCPSApplicationException {
		GeneralDao.update(_em, ba);
	}
	
	@Override
	public BankAssoc getAppContractBankByPk(BankAssoc ba) {
		return _em.find(BankAssoc.class, ba);
	}
}

